package com.borrow.jiemihua.mainUI.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.borrow.jiemihua.BuildConfig;
import com.borrow.jiemihua.R;
import com.borrow.jiemihua.base.BaseActivity;
import com.borrow.jiemihua.base.BaseApplication;
import com.borrow.jiemihua.base.BaseConstant;
import com.borrow.jiemihua.mainUI.MainActivity;
import com.borrow.jiemihua.mainUI.activity.LoginRegister.LoginActivity;
import com.borrow.jiemihua.utils.SharedPreferencesUtils;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.activity_setting)
public class SettingActivity extends BaseActivity {
    @ViewInject(R.id.tv_top_title)
    private TextView     tv_top_title;
    @ViewInject(R.id.tv_visson)
    private TextView     tv_visson;
    @ViewInject(R.id.service)
    private LinearLayout service;
    @ViewInject(R.id.time)
    private TextView     time;
    @ViewInject(R.id.hujiao)
    private TextView     hujiao;
    private boolean      isphone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        BaseApplication.addDestoryActivity(this, "login1");
        initData();
        initView();
    }

    @Override
    protected void initView() {
        tv_visson.setText("v" + BuildConfig.VERSION_NAME);
    }

    @Override
    protected void initData() {
        tv_top_title.setText("设置");
    }

    @Event(value = {R.id.imgbtn_left, R.id._tv_login_out, R.id.rl_kfrx, R.id.hujiao, R.id.quxiao, R.id.rl_opinion}, type = View.OnClickListener.class)
    private void getEvent(View view) {
        switch (view.getId()) {
            case R.id.imgbtn_left:
                finish();
                break;
            //退出登陆
            case R.id._tv_login_out:
                BaseApplication.getInstance().removerUser();
                jumpActivity(LoginActivity.class, null, false);
                break;
            case R.id.rl_kfrx:
                //                isphone=true;
                //                time.setText("客服热线");
                //                hujiao.setText("呼叫：0571-56051483");
                //                service.setVisibility(View.VISIBLE);
                break;
            case R.id.hujiao:
                if (isphone == true) {
                    Intent intent = new Intent(Intent.ACTION_DIAL);
                    Uri datav = Uri.parse("tel:" + "0571-56051483");
                    intent.setData(datav);
                    startActivity(intent);
                }
                break;
            case R.id.rl_opinion:
                isphone = false;
                time.setText("合作邮箱");
                hujiao.setText("1584165326@qq.com");
                service.setVisibility(View.VISIBLE);
                break;
            case R.id.quxiao:
                service.setVisibility(View.GONE);
                break;
            default:
                break;

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        String userid = SharedPreferencesUtils.getString(this, BaseConstant.SPConstant.USERID, "");
        if (!userid.equals("") && userid != null) {
            return;
        } else {
            startActivity(new Intent(this, MainActivity.class));
        }
    }
}
